<div class="main-content">
    <div class="section__content section__content--p20">
        <div class="container-fluid">
            <div class="row m-b-30">
                <div class="col-lg-12">
                    <div class="overview-wrap">
                        <h2 class="title-1">在线交流</h2>
                        <button class="au-btn au-btn-icon au-btn--blue"  onclick="showedit()">
                            <i class="zmdi zmdi-plus"></i>添加在线交流</button>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <div class="table-responsive table--no-card m-b-30">
                        <table class="table table-borderless table-striped table-earning">
                            <thead>
                            <tr>
                                <th>标题</th>
                                <th>QQ</th>
                                <th>淘宝旺旺</th>
                                <th>MSN</th>
                                <th>排序</th>
                                <th>工具</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php
                            if (sizeof($onlines) > 0) {
                                foreach ($onlines as $o) {
                                    ?>
                                    <tr>
                                        <td><?php echo $o['name']; ?></td>
                                        <td><?php echo $o['qq']; ?></td>
                                        <td><?php echo $o['taobaowangwang']; ?></td>
                                        <td><?php echo $o['msn']; ?></td>
                                        <td><?php echo $o['seq']; ?></td>
                                        <td>
                                            <button type="button" class="btn btn-primary btn-sm"  onclick="showedit(<?php echo $o['online_id']; ?>)" >编辑</button>
                                            <button type="button" class="btn btn-danger btn-sm"  data-toggle="modal" data-target="#confirmModal" onclick="del(<?php echo $o['online_id']; ?>)">删除</button>

                                        </td>
                                    </tr>
                                    <?php
                                }
                            }
                            ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

            <div class="row" id="forn_online" style="display: none;">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-header">
                            <strong>在线交流编辑</strong>
                        </div>
                        <div class="card-body">
                            <form class="form-horizontal" role="form" name="form" id="form" method="post"
                                  data-bv-feedbackicons-valid="glyphicon glyphicon-ok"
                                  data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
                                  data-bv-feedbackicons-validating="glyphicon glyphicon-refresh"
                                  action="index.php?r=admin/online/edit">
                                <input type="hidden" name="YII_CSRF_TOKEN"
                                       value="<?php echo Yii::app()->request->csrfToken; ?>"/>
                                <input type="hidden" name="online_id"/>

                                <div class="form-group">
                                    <label class=" form-control-label">标题</label>
                                    <input type="text" class="form-control" name="name"/>
                                </div>

                                <div class="form-group">
                                    <label class=" form-control-label">QQ</label>
                                    <input type="text" class="form-control" name="qq"/>
                                </div>

                                <div class="form-group">
                                    <label class=" form-control-label">淘宝旺旺</label>
                                    <input type="text" class="form-control" name="taobaowangwang"/>
                                </div>

                                <div class="form-group">
                                    <label class=" form-control-label">MSN</label>
                                    <input type="text" class="form-control" name="msn"/>
                                </div>

                                <div class="form-group">
                                    <label class=" form-control-label">排序</label>
                                    <input type="text" class="form-control"
                                           name="seq"/>
                                </div>

                                <div class="form-group">
                                    <button  type="submit" name="submit" id="submit" class="btn btn-primary btn-lg btn-block">保存</button>
                                </div>

                            </form>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>
<script>
    $(function () {
        initPage();
    });
    function initPage() {
        $('#form').bootstrapValidator();
        $('#form').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (formData, jqForm, options) {
                return $('#form').data('bootstrapValidator').isValid();
            },
            success: function (res) {
                if (message(res)) {
                    window.location.href = "index.php?r=admin/online/index";
                }
            }
        });
    }
    function showedit(id) {
        current = id;
        if (id != null) {
            title = "在线交流编辑";

            $.get('index.php?r=admin/online/json&id='+id,null,function (res) {
                if(message(res)){
                    $("input[name=online_id]").val(res.data.online_id);
                    $("input[name=name]").val(res.data.name);
                    $("input[name=seq]").val(res.data.seq);
                    $("input[name=qq]").val(res.data.qq);
                    $("input[name=taobaowangwang]").val(res.data.taobaowangwang);
                    $("input[name=msn]").val(res.data.msn);
                }
            },'json');
            $("#forn_online").show()
        } else {
            title = "在线交流添加";
            $("#toolbar").hide();
            $("#forn_online").show();
            $("#datalist").hide();
        }
    }
    function del(id) {
        $("#confirmModal_text").text('删除在线交流？');
        $("#confirmModalButton").bind("click",function () {
            $.get("index.php?r=admin/online/del&id=" + id,null,function (res) {
                if(message(res)){
                    window.location.reload();
                }
            },'json');
        });
    }
</script>